package com.mf.all.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mf.all.entity.dto.TaskDetailBo;
import com.mf.all.service.ITaskDetailService;
import com.mf.all.mapper.TaskDetailMapper;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;

/**
 * 任务汇报明细 服务实现类
 *
 * @author mf
 * @since 2025-03-08
 */
@Service
public class TaskDetailServiceImpl extends ServiceImpl<TaskDetailMapper, TaskDetailBo> implements ITaskDetailService {
    /**
     * 查询任务id查询汇报明细
     */
    @Override
    public List<TaskDetailBo> findListById(int taskId) {
        final LambdaQueryWrapper<TaskDetailBo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(TaskDetailBo::getTaskId, taskId);
        wrapper.orderByDesc(TaskDetailBo::getCreatedTime);
        return baseMapper.selectList(wrapper);
    }

    /**
     * 根据任务id查询指定日期有没有汇报明细
     */
    @Override
    public List<TaskDetailBo> findByTaskIdAndNotificationDate(Integer taskId, LocalDate notificationDate) {
        final LambdaQueryWrapper<TaskDetailBo> wrapper1 = new LambdaQueryWrapper<>();
        // 查询任务详情当天有没有汇报（当前有创建那么就是有汇报）
        final LocalDateTime startOfDay = notificationDate.atStartOfDay(); // 当天的开始时间 00:00:00
        final LocalDateTime endOfDay = notificationDate.atTime(LocalTime.MAX); // 当天的结束时间 23:59:59

        wrapper1.eq(TaskDetailBo::getTaskId, taskId)
                .ge(TaskDetailBo::getCreatedTime, startOfDay) // 大于等于当天的开始时间
                .le(TaskDetailBo::getCreatedTime, endOfDay);  // 小于等于当天的结束时间
        return baseMapper.selectList(wrapper1);
    }
}
